package ch.zbw.rre.stack;

public class StackSimpleArray implements StackArray{

	private final int MAX = 10;
	private Element stack[] = new Element [MAX];
	private int stackPointer = 0;
	
	public StackSimpleArray() {
		this.stackPointer = 0;
	}

	@Override
	public boolean push(Element obj) {
		if (checkFull() == false){
			stack[stackPointer] = obj;
			stackPointer ++;
			return true;
		}
		return false;
	}

	@Override
	public Element pop() {
		if (empty() == false){
			Element temp;
			temp = stack[stackPointer-1];
			stack[stackPointer-1] = null;
			stackPointer --;
			return temp;
		}
		return null;
	}

	@Override
	public Element top(){
		if (empty() == false){
			return stack[stackPointer-1];
		}
	return null;
}
	
	
	@Override
	public boolean empty() {
		if(stackPointer == 0){
			return true;
		}
		return false;
	}

	public boolean checkFull(){
		if(stackPointer == MAX ){
			return true;
		}
		return false;
	}
}
